package com.example.demo.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import javax.security.auth.Subject;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

public class UserAuthentication implements Authentication, Serializable {

    private Long userId;

    private String userName;
    private String password;

    private Object principal;
    private Object credentials;

    private Boolean isAuthenticated;

    private Collection<? extends GrantedAuthority> authorities;
    //用户名密码构造
    public UserAuthentication(Object credits, Object principal) {
        this.credentials = credits;
        this.principal = principal;
    }
    //用户名密码权限列表构造

    public UserAuthentication(Object principal, Object credits, Collection<? extends GrantedAuthority> authorities) {
        this.principal = principal;
        this.credentials = credits;
        this.authorities = authorities;
    }
    //登陆后缓存对象
    public UserAuthentication(Object principal, Object credentials, Boolean isAuthenticated) {
        this.principal = principal;
        this.credentials = credentials;
        this.isAuthenticated = isAuthenticated;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public void setPrincipal(Object principal) {
        this.principal = principal;
    }


    public void setCredits(Object credits) {
        this.credentials = credits;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    @Override
    public boolean implies(Subject subject) {
        return Authentication.super.implies(subject);
    }

    @Override
    public String getName() {
        return "";
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public Object getCredentials() {
        return credentials;
    }

    @Override
    public Object getDetails() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }

    @Override
    public boolean isAuthenticated() {
        return this.isAuthenticated;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        this.isAuthenticated=isAuthenticated;
    }
}
